package com.neuedu.service.impl;

import com.neuedu.dao.RenYuanDao;
import com.neuedu.dao.impl.RenYuanDaoImpl;

import com.neuedu.model.RenYuan;
import com.neuedu.service.RenYuanService;
import com.neuedu.vo.PageVO;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class RenYuanServiceImpl implements RenYuanService {
    RenYuanDao renYuanDao=new RenYuanDaoImpl();
    @Override
    public PageVO<RenYuan> selectOnePage(Integer pageNo, Integer pageSize, String startTime, String endTime, String name) {
        Integer limitParams1=(pageNo-1)*pageSize;
        Integer limitParams2=pageSize;
        List<RenYuan> renYuans = renYuanDao.selectPageList(limitParams1, limitParams2, startTime, endTime, name);
        int count = renYuanDao.selectCount(startTime, endTime, name);

        PageVO<RenYuan> pageVO=new PageVO<>();
        pageVO.setCount(count);
        pageVO.setData(renYuans);
        pageVO.setPageNo(pageNo);
        pageVO.setPageSize(pageSize);
        pageVO.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        return pageVO;
    }

    @Override
    public int add(RenYuan renYuan) {
        //XY20240319001
        Date date = new Date();
        SimpleDateFormat chuangjianshijianSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String chuangjianshijian=chuangjianshijianSdf.format(date);
        renYuan.setChuangjianshijian(chuangjianshijian);

        return renYuanDao.add(renYuan);
    }

    @Override
    public RenYuan findRenYuanById(Integer id) {
        return renYuanDao.selectRenYuanOne(id);
    }

    @Override
    public int editRenYuanInfo(RenYuan renYuan) {
        return renYuanDao.updateRenYuan(renYuan);
    }
}
